//路由的配置信息

//引入一级路由组件
// import Home from '@/pages/Home'
// import Search from '@/pages/Search'
// import Login from '@/pages/Login'
// import Register from '@/pages/Register'
// import Detail from '@/pages/Detail'
// import AddCartSuccess from '@/pages/AddCartSuccess'
// import ShopCart from '@/pages/ShopCart'
// import Trade from '@/pages/Trade'
// import Pay from '@/pages/Pay'
// import PaySuccess from '@/pages/PaySuccess'
// import Center from '@/pages/Center'
// //引入二级路由组件
// import MyOrder from '@/pages/Center/myOrder'
// import GroupOrder from '@/pages/Center/groupOrder'

// 路由懒加载: 当打包构建应用时JS包会变得非常大，影响页面加载。
// 如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就更加高效了
// component: ()=>import('@/pages/Home'),

export default [
    {
        path: '/center',
        component: () => import('@/pages/Center'),
        meta: { show: true },
        children: [
            {
                path: 'myorder',
                component: () => import('@/pages/Center/myOrder'),
            },
            {
                path: 'grouporder',
                component: () => import('@/pages/Center/groupOrder'),
            },
            //重定向,在进入订单中心的时候直接重定向到我的订单
            {
                path: "/center",
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: '/paysuccess',
        component: () => import('@/pages/PaySuccess'),
        meta: { show: true }
    },
    {
        path: '/pay',
        component: () => import('@/pages/Pay'),
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //想去订单提交成功的待支付页面,必须是从结算页面而来
            if (from.path == '/trade') {
                next()
            } else {
                // 其余的一律劝返
                next(false)
            }
        }
    },
    {
        path: '/trade',
        component: () => import('@/pages/Trade'),
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //想去交易页面,必须是从购物车而来
            if (from.path == '/shopcart') {
                next()
            } else {
                // 其余的一律劝返
                next(false)
            }
        }
    },
    {
        path: '/shopcart',
        // name: 'shopcart',
        component: () => import('@/pages/ShopCart'),
        meta: { show: true }
    },
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: () => import('@/pages/AddCartSuccess'),
        meta: { show: true }
    },
    {
        path: '/detail/:skuid',
        component: () => import('@/pages/Detail'),
        meta: { show: true }
    },
    {
        path: '/home',
        component: () => import('@/pages/Home'),
        meta: { show: true }
    },
    {
        name: 'search',
        path: '/search/:keyword?',
        component: () => import('@/pages/Search'),
        meta: { show: true },
        // 面试题4:路由组件能不能传递props数据?
        // 可以的:三种写法

        // 布尔值写法: 只能传递params参数
        // props: true,

        // 对象写法:额外给路由传递一些固定死的数据
        // props: { a: 1, b: 2 }

        // 函数写法:可以把params和query参数传递给路由组件
        props: ($route) => ({
            keyword: $route.params.keyword,
            k: $route.query.k,
        })
    },
    {
        path: '/login',
        component: () => import('@/pages/Login'),
        meta: { show: false }
    },
    {
        path: '/register',
        component: () => import('@/pages/Register'),
        meta: { show: false }
    },
    //重定向,在项目跑起来的时候访问/, 立刻定向到主页
    {
        path: "*",
        redirect: '/home'
    }
]